<?php
class Index extends Controller {
	public function html() {
		$mUser = new User_model();
		$currUser = $mUser->currUser();
		if(!$currUser) header('Location:/auth/login?backurl='.urlencode('/yunying/product/'));
		
		$data = array();
		$tpl = 'yunying/product/index.html';
		
		$hot = $this->get('hot', 'int');
		$recommend = $this->get('recommend', 'int');
		$province = $this->get('province', 'int');
		$city = $this->get('city', 'int');
		$name = $this->get('name', 'str');
		
		$page = $this->get('page', 'str', 1);
		$size = 20;
		
		$params = array();
		if($hot) $params['hot'] = 1;
		if($recommend) $params['recommend'] = 1;
		if($province) $params['province'] = $province;
		if($city) $params['city'] = $city;
		if($name) $params['name like'] = '%'.$name.'%';
		
		$data['hot'] = $hot;
		$data['recommend'] = $recommend;
		$data['province'] = $province;
		$data['city'] = $city;
		$data['name'] = $name;
		
		$mProduct = new Product_model();
		$data['product'] = $mProduct->page($page, $size, $params);
		
		$this->display($data, $tpl);
	}
}